package file;

import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class FileWay {
    public static void main(String[] args) throws IOException {
        //判断，获取
        File f1 = new File("D:\\not\\xuruiqi\\a.txt");
        System.out.println(f1);
        System.out.println("=======================");
        //判断文件
        boolean directory = f1.isDirectory();
        System.out.println(directory);
        System.out.println("=======================");
        boolean file = f1.isFile();
        System.out.println(file);
        System.out.println("=======================");
        boolean exists = f1.exists();
        System.out.println(exists);
        //判断文件夹
        File f2 = new File("D:\\not\\xuruiqi");
        System.out.println(f2);
        System.out.println("=======================");
        //判断文件
        boolean directory2 = f2.isDirectory();
        System.out.println(directory2);
        System.out.println("=======================");
        boolean file2 = f2.isFile();
        System.out.println(file2);
        System.out.println("=======================");
        boolean exists2 = f2.exists();
        System.out.println(exists2);
        //判断路径是否存在
        File f3 = new File("D:\\not\\xurui");
        System.out.println(f3);
        System.out.println("=======================");
        //判断文件
        boolean directory3 = f3.isDirectory();
        System.out.println(directory3);
        System.out.println("=======================");
        boolean file3 = f3.isFile();
        System.out.println(file3);
        System.out.println("=======================");
        boolean exists3 = f3.exists();
        System.out.println(exists3);
        //文件字节数
        System.out.println("=======================");
        long length = f1.length();
        System.out.println(length);
        //返回文件的绝对路径
        System.out.println("=======================");
        String absolutePath = f1.getAbsolutePath();
        System.out.println(absolutePath);
        System.out.println("=======================");
        //返回定义文件时使用的路径
        String path = f1.getPath();
        System.out.println(path);
        //返回文件名，带后缀
        System.out.println("=======================");
        String name = f1.getName();
        System.out.println(name);
        System.out.println("=======================");
        //返回文件修改时间（时间毫秒值）
        long l = f1.lastModified();
        System.out.println(l);
        Date date = new Date(l);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String format = sdf.format(date);
        System.out.println(format);
        System.out.println("=======================");
        //创建，删除
        File f4 = new File("D:\\not\\xuruiqi\\b");
        boolean newFile = f4.createNewFile();
        System.out.println(newFile);
        System.out.println("=======================");
        File f5 = new File("D:\\not\\bbb");
        boolean mkdir = f5.mkdir();
        System.out.println(mkdir);
        System.out.println("=======================");

        File f6 = new File("D:\\not\\bbb\\ccc\\ddd");
        boolean mkdirs = f6.mkdirs();
        System.out.println(mkdirs);
        boolean delete = f6.delete();
        System.out.println(delete);
        System.out.println("=======================");
        File[] files = f5.listFiles();
        for (File file1 : files) {
            System.out.println(file1);
        }
    }
}
